package com.diankangwo.factory.service.impl;

import com.diankangwo.factory.dao.TdTypeMapper;
import com.diankangwo.factory.entity.TdType;
import com.diankangwo.factory.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/** 一级分类
 * Created by wuye on 2017/9/11.
 */
@Service("TypeService")
public class TypeServiceImpl implements TypeService{

    @Autowired
    private TdTypeMapper mapper;

    @Override
    public TdType queryById(int id) {
        return mapper.selectByPrimaryKey(id);
    }

    /**一级分类列表
     * 获取
     * @param map
     * @return
     */
    @Override
    public List<TdType> queryList(Map<String, Object> map) {
        return mapper.queryList(map);
    }

    /**
     * 查询总数
     * @param map
     * @return
     */
    public int queryTotal(Map<String,Object> map){
        return mapper.queryTotal(map);
    }

    /**
     * 保存一级分类
     * @param type
     */
    @Override
    public void save(TdType type) {
        mapper.insert(type);
    }

    /**
     * 修改
     * @param tdType
     * @return
     */
    @Override
    @Transactional
    public int update(TdType tdType) {
        return mapper.updateByPrimaryKey(tdType);
    }

    @Override
    public List<TdType> queryAll() {
        return mapper.queryAll();
    }

    /**
     * 删除
     * @param tdType
     */
    @Override
    @Transactional
    public void deleteBatch(TdType tdType) {
        mapper.deleteBatch(tdType);
    }

    /**
     * 根据ID删除
     * @param id
     */
    @Override
    @Transactional
    public void deleteById(int id) {
        mapper.deleteById(id);
    }
}
